<template>
	<view class="content">
		<view v-if="title" class="title">{{title}}</view>
		<swiper :style="{height:sHeight}" class="swiper" :indicator-dots="false" :autoplay="false" :duration="500"
			indicator-active-color="#bcbcbc" @change="change" indicator-color="#e6e6e6">
			<swiper-item v-for="(list,i) in menuList" :key="i">
				<view class="menu">
					<view class="menu-1" v-for="(menus,index1) in list" :key="index1">
						<u-row>
							<u-col :span="coln" v-for="(menu,index) in menus" :index="index"
								@click="goCard(menu.url,menu.appid)">
								<view class="u-flex u-col-center u-row-center u-flex-wrap">
									<view class="u-flex u-row-center u-col-center" style="width: 80rpx;height: 80rpx;">
										<image :src="menu.image" style="width: 80rpx;height: 80rpx;" />
									</view>
									<view class="menu_item u-line-1" style="color:#000">{{menu.title}}</view>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import {
		goNav
	} from '@/lib/Comment.js'
	export default {
		data() {
			return {
				current: 0
			}
		},
		props: {
			list: {
				type: Array,
				default: () => {
					return []
				}
			},
			col: {
				type: Number,
				default: 2
			},
			size: {
				type: Number,
				default: 5
			},
			title: {
				type: String,
				default: ''
			}
		},
		computed: {
			sHeight() {
				if (this.menuList.length > this.current) {
					let num = this.menuList[this.current].length * 150
					return num + 'rpx';
				} else {
					return '150rpx'
				}

			},
			menuList() {
				let data = this.parseMenu(this.list, this.size * this.col);
				for (let i = 0; i < data.length; i++) {
					data[i] = this.parseMenu(data[i], this.size)
				}
				return data
			},
			coln() {
				return 12 / this.size
			}

		},
		methods: {
			change(current) {
				let i = current.detail.current
				this.$set(this, 'current', i)
			},
			parseMenu(list, size) {
				let menu = [];
				let count = Math.ceil(list.length / size);
				for (let i = 1; i <= count; i++) {
					let data = list.slice((i - 1) * size, i * size)
					menu.push(data)
				}
				return menu;
			},
			goCard(url, appid) {
				if (appid) {
					uni.navigateToMiniProgram({
						appId: appid,
						path: url,
						envVersion: 'release'
					})
				} else {
					goNav(url)
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.menu {
		//padding: 20rpx 0;		
	}

	.menu-1 {
		line-height: 70rpx;
		height: 150rpx;
	}

	.menu_item {
		line-height: 60rpx;
		text-align: center;
		font-size: 24rpx;
		width: 140rpx;
	}

	.swiper {}

	.title {
		line-height: 80rpx;
		padding-left: 20rpx;
	}

	.content {
		padding-top: 20rpx;
	}
</style>